package com.itheima.reggie.mapper;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.reggie.entity.Setmeal;
import com.itheima.reggie.entity.SetmealVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

public interface SetmealMapper extends BaseMapper<Setmeal> {

    List<SetmealVo> findPage(@Param("page") Integer page, @Param("pageSize")Integer pageSize, @Param("name") String name);

   Integer findCount(@Param("name") String name);

    int removeIds(@Param("ids") List<Long> ids, @Param("updateTime") LocalDateTime updateTime, @Param("updateUser") Long updateUser);

    @Update("<script>" +
            " UPDATE setmeal SET status = #{status},update_time = #{updateTime},update_user = #{updateUser} where id in" +
            "<foreach collection=\"ids\" index=\"index\" item=\"id\" open=\"(\" separator=\",\" close=\")\">\n" +
            " #{id} \n" +
            "</foreach>" +
            "</script>")
    void editStatus(@Param("status") Integer status, @Param("ids") List<Long> ids, @Param("updateTime") LocalDateTime updateTime, @Param("updateUser") Long updateUser);

    @Select("SELECT sum(a.price) AS `value`, b.`name` FROM setmeal a INNER JOIN category b ON a.category_id = b.id GROUP BY a.category_id")
    public List<JSONObject> selectEachAnalysis();
}
